﻿using System;
using Ooaavee.Scripting.Remoting;

namespace DevelopersTestPad.Remoting
{
    [Serializable]
    public abstract class DevelopersTestPadRemoteScript : RemoteScript
    {
        /// <summary>
        /// Occurs when a script should be initialized.
        /// </summary>
        protected override void InitializeScript()
        {            
            if (base.Parameters.Count != 1)
            {
                throw new InvalidOperationException("Invalid Parameters Count.");
            }

            DevelopersTestPadParameters p = base.Parameters[0] as DevelopersTestPadParameters;
            if (p == null)
            {
                throw new InvalidOperationException("DevelopersTestPadParameters object is missing.");
            }

            ExtensionEngine.Initialize(this, p);

            if (p.ConsoleStandardOutputStream != null)
            {
                Console.SetOut(p.ConsoleStandardOutputStream);
            }

            if (p.ConsoleStanrardInputStream != null)
            {
                Console.SetIn(p.ConsoleStanrardInputStream);
            }
        }
    }
}
